package com.fh.shop.api.book.controller;

import com.fh.shop.api.book.biz.IBookService;
import com.fh.shop.api.book.param.BookQueryParam;
import com.fh.shop.api.book.po.Book;
import com.fh.shop.api.common.DataTableResult;
import com.fh.shop.api.common.ServerResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/api/book")
@RestController
@CrossOrigin
public class BookController {
    @Resource(name = "bookService")
    private IBookService bookService;

    @PostMapping("/add")
    public ServerResponse add(Book book){
        return bookService.addBook(book);
    }

    @PostMapping("/list")
    public ServerResponse list(){
        return bookService.findBookList();
    }

    @PostMapping("/delete")
    public ServerResponse delete(Long id){
        return bookService.deleteBook(id);
    }

    @PostMapping("/deleteBatch")
    public ServerResponse deleteBatch(String ids){
        return bookService.deleteBatch(ids);
    }

    @GetMapping("/find")
    public ServerResponse findBook(Long id){
        return bookService.findBook(id);
    }

    @PostMapping("/update")
    public ServerResponse updateBook(Book book){
        return bookService.updateBook(book);
    }

    @PostMapping("/findList")
    public DataTableResult findList(BookQueryParam bookQueryParam){
        return bookService.findList(bookQueryParam);
    }
}
